package com.tyc.flink;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * 类描述
 *
 * @author tyc
 * @version 1.0
 * @date 2022-11-16 17:45:06
 */
public class Transform_1_Map {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<Integer> dataStreamSource = env.fromCollection(Arrays.asList(10, 20, 30, 11, 12, 13));

        //map 匿名类写法
        SingleOutputStreamOperator<Integer> map = dataStreamSource.map((MapFunction<Integer, Integer>) integer -> integer*2);
        map.print("map");

        //map lambda写法
        SingleOutputStreamOperator<Integer> map2 = dataStreamSource.map((Integer a) -> a*2);
        map2.print();

        env.execute();
    }
}
